﻿using Link.EntityFramework.Sqlite;
using Memorandum.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Memorandum.DBContext
{
    public sealed class SettingConfiguration : DbMigrationsConfiguration<SqliteDBContext>
    {
        public SettingConfiguration()
        {
            AutomaticMigrationsEnabled = true;//自动迁移
            AutomaticMigrationDataLossAllowed = true;//强制自动迁移——丢失数据
        }

        protected override void Seed(SqliteDBContext context)
        {

        }
    }
    public class SqliteDBContext:DbContext
    {
        public SqliteDBContext() : base("name=sqliteConnect") { }
        public DbSet<RemindItem> RemindItems
        {
            set;
            get;
        }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            Database.SetInitializer(new CreateDatabaseIfNotExists<SqliteDBContext>());
            //Database.SetInitializer<SqliteDBContext>(new MigrateDatabaseToLatestVersionExtention<SqliteDBContext, SettingConfiguration>(true));
            //var sqliteConnectionInitializer = new SqliteCreateDatabaseIfNotExists<MyDbContext>(
            //Database.Connection.ConnectionString, modelBuilder);
            // Database.SetInitializer(sqliteConnectionInitializer);
            //modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            base.OnModelCreating(modelBuilder);
        }
        private static SqliteDBContext instance;
        public static SqliteDBContext Instance
        {
            get
            {
                if(instance==null)
                {
                    instance = new SqliteDBContext();
                }
                return instance;
            }
        }
    }
}
